package com.ahdms.es.result;

import com.ahdms.es.bean.IAlertAble;

/**
 * @author qinxiang
 * @date 2021-04-13 11:25
 */
public class VerifyResult<T> {

    private boolean result;

    private String errorMsg;

    private int code;

    private T data;

    public VerifyResult() {
    }

    public VerifyResult(boolean result, String errorMsg, int code) {
        this.result = result;
        this.errorMsg = errorMsg;
        this.code = code;
    }

    public VerifyResult(boolean result, String errorMsg, int code, T data) {
        this.result = result;
        this.errorMsg = errorMsg;
        this.code = code;
        this.data = data;
    }

    public static VerifyResult success() {
        return new VerifyResult(true, null, 0);
    }

    public static <T> VerifyResult success(T data) {
        return new VerifyResult(true, null, 0, data);
    }

    public static VerifyResult error(String errorMsg) {
        return new VerifyResult(false, errorMsg, 1);
    }

    public static VerifyResult error(IAlertAble alertAble) {
        return new VerifyResult(false, alertAble.getMessage(), alertAble.getCode());
    }

    public static VerifyResult error(String errorMsg, int code) {
        return new VerifyResult(false, errorMsg, code);
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
